package com.panshi.controller;

import com.panshi.service.IMessagService;
import com.panshi.vo.qa.DataResultQA;
import com.panshi.vo.qa.Messag;
import com.panshi.vo.qa.Pages;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/messag",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class MessagController {

    @Autowired
    IMessagService messagService;

    //评论添加
    @PostMapping("/addMessag")
    DataResultQA addMessag(@RequestBody Messag messag){
        log.info("请求路径：{},参数：{}","/messag/addMessag",messag);
        return messagService.addMessag(messag);
    }

    //分页查询评论
    @PostMapping("/inquirePagesMessag")
    DataResultQA<List<Messag>> inquirePagesMessag(@RequestBody Pages pages){
        log.info("请求路径：{},参数：{}","/messag/inquirePagesMessag",pages);
        DataResultQA<List<Messag>> dataResultQA = messagService.inquirePagesMessag(pages);
        System.out.println("======================"+dataResultQA);
        return dataResultQA;
    }

    //查询总数
    @GetMapping("/inquireSum/{userId}")
    DataResultQA<Integer> inquireSum(@PathVariable int userId){
        log.info("请求路径：{},参数：{}","/messag/inquirePagesMessag",userId);
        DataResultQA<Integer> dataResultQA = messagService.inquireSum(userId);
        return dataResultQA;
    }

    //修改站内消息
    @PostMapping("/updateMessag")
    DataResultQA updateMessag(@RequestBody Messag messag){
        log.info("请求路径：{},参数：{}","/messag/updateMessag",messag);
        DataResultQA dataResultQA = messagService.updateMessag(messag);
        return dataResultQA;
    }

    //已读
    @PostMapping("/messagMsgRead/{id}")
    DataResultQA messagMsgRead(@PathVariable Integer id){
        log.info("请求路径：{},参数：{}","/messag/messagMsgRead/{id}",id);
        DataResultQA dataResultQA = messagService.messagMsgRead(id);
        return dataResultQA;
    }
}
